<extend name="Base/common" />
<block name="body">
	<!--导航引用-->
	<include file="Public/nav" />
	
	<section class="ui-container">
		<empty name="list">
			<!--s not goods-->
			<section class="ui-not-goods-wrap ui-whitespace">
				<div class="ui-cart-not-goods">
				    <i class="iconfont">&#xf620;</i>
				    <p>暂无订单信息(ㄒoㄒ)~~</p>
				    <div class="ui-btn-group">
				        <a class="ui-btn-primary ui-btn" onclick="goHome();">去选购</a>
				    </div>
			    </div>
			</section><!--e not goods-->
		<else />
			<volist name="list" id="v">
				<!-- 待支付开始 -->
				<div class="ui-list-pay-state">
						<h5 class="ui-title">
							<b>订单状态</b>
							<b class="ui-txt-highlight">
								<switch name="v.order_status">
									<case value="0">等待买家付款</case>
									<case value="1">付款确认中</case>
									<case value="2">买家已付款</case>
									<case value="3">卖家已发货</case>
									<case value="4">交易成功</case>
									<case value="5">交易关闭</case>
									<case value="6">交易完成</case>
								</switch>
							</b>
						</h5>
						<ul class="ui-list-goods-cart ui-whitespace ui-border-tb">
							<li class="ui-tiled ui-border-b">
								<!-- <div class="ui-list-goods-img">
						            <img src="{$vo.picture||get_cover='path'}" width="50" height="50"/>
						        </div> -->
						        <div class="ui-list-goods-info" style="margin-left:0;">
						        	<h5>订单号：{$v.order_id}</h5>
						        	<p class="ui-goods-size-color"><span>下单时间：{$v.ctime|time_format=###,'Y-m-d'}</span></p>
						        	<p class="ui-goods-size-color"><span>订单金额：￥{$v.pock_money}</span></p>
						        </div>
							</li>
						</ul>
						<div class="ui-pay-state-btn">
							<div class="ui-btn-group ui-flex-pack-end">
								<switch name="v.order_status">
									<case value="0">
										<a href="#" class="ui-btn-s ui-btn-primary" onclick="payNow('{$v.pock_money}', '{$v.zhekouAll}', '{$v.order_id}', {$data.shop_id}, {$data.user_id});">去支付</a>
										<a href="#" class="ui-btn-s ui-btn-danger cancel_order" dorder="{$v.order_id}">取消订单</a>
									</case>
									<case value="1"></case>
									<case value="2"></case>
									<case value="3">
										<a href="{:U('querywuliu', array('order_id' => $v['order_id']))}" class="ui-btn-s ui-btn-primary">查看物流</a>
										<a href="#" class="ui-btn-s ui-btn-primary shouhuo" d_order_id="{$v.order_id}">确认收货</a>
									</case>
									<case value="4">
										<eq name="v.is_take" value="0">
											<if condition="$v.return_count gt 0">
												<a class="ui-btn-s ui-btn-primary" href="javascript::">退货中...</a>
											<elseif condition="$v.return_success_count gt 0" />
												<a class="ui-btn-s ui-btn-primary" href="javascript::">退货完成</a>
											<elseif condition="$v.return_cancel_count gt 0" />
												<a class="ui-btn-s ui-btn-primary" href="javascript::">已取消</a>
											<else />
												<a _href="{:U('ReturnGoods/index', array('order_id' => $v['order_id'], 'type' => 'ALL', 'return_money' => $v['pock_money']))}" class="ui-btn-s ui-btn-primary user_return_goods">申请退货</a>
												<a href="javascript::" class="ui-btn-s ui-btn-primary sure_not_goods" d_order_id="{$v.order_id}">确认不退货</a>
											</if>
										</eq>
									</case>
								</switch>
								<a class="ui-btn-s ui-btn-primary" href="{:U('order_detail', array('order_id' => $v['order_id']))}">查看详情</a>
							</div>
						</div>
					<!-- 待支付结束 -->
				</div>	
			</volist>
		</empty>

		<div class="ui-actionsheet">  
		  <div class="ui-actionsheet-cnt">
		    <h4>请选择取消订单的理由</h4> 
		    <button>我不想买了</button>  
		    <button>信息填写错误，重新拍</button>  
		    <button>卖家缺货</button>  
		    <button>面对面交易</button>  
		    <button>其他原因</button>  
		    <button>取消</button> 
		  </div>         
		</div>
	</section>
</block>
<block name="script">
	<script type="text/javascript">
		var order_id = '';
		//取消订单
		$('.cancel_order').click(function(){
			order_id = '';
			order_id = $(this).attr('dorder');
			$('.ui-actionsheet').addClass('show');
		});

		$('.ui-actionsheet div button').click(function(){
			var return_msg = $(this).html();
			if(return_msg=='取消'){
				$('.ui-actionsheet').removeClass('show');
			}else{
				$.get("{:U('cancel_order')}", {
					order_id: order_id,
					return_msg: return_msg
				}, function(r) {
					if (r.status) {
						$.tips({
					        content:'取消订单成功！',
					        stayTime:2000,
					        type:"success"
					    });
						window.location.reload();
					} else {
						$.tips({
					        content:'服务器连接失败',
					        stayTime:2000,
					        type:"success"
					    });
					    $('.ui-actionsheet').removeClass('show');
					}
				}, 'json');
			}
		});

		//收货
		$('.shouhuo').click(function(){
			var order_id = $(this).attr('d_order_id');
			sureGoods(order_id, 0, '确认收货？');
			
		});
		//收货不退货
		$('.shouhuo_no_return').click(function(){
			var order_id = $(this).attr('order_id_no');
			sureGoods(order_id, 1, '确认收获不退货？');
		});
		
		function sureGoods(order_id, type, msg){
			var dia=$.dialog({
		        title:'温馨提示',
		        content: msg,
		        button:["确认","取消"]
		    });
		    dia.on("dialog:action",function(e){
		    	if(e.index == 0){
		    		$.ajax({
		                url: "{:U('sureGoods')}",
		                type: 'post',
		                data: {
		                    order_id: order_id,
		                    type: type
		                },
		                dataType: 'json',
		                error: function () {
		                    $.tips({
						        content:'服务器连接失败',
						        stayTime:2000,
						        type:"success"
						    });
		                }, success: function (data) {
		                    if (data.status) {
		                        $.tips({
							        content:data.info,
							        stayTime:2000,
							        type:"success"
							    });

		                        document.location.reload();//当前页面  
		                    } else {
		                        $.tips({
							        content:data.info,
							        stayTime:2000,
							        type:"success"
							    });

		                    }
		                }
		            });
		    	}
		    });
		    dia.on("dialog:hide",function(e){
		        console.log("dialog hide")
		    });
		}
		
		$('.sure_not_goods').tap(function(){
			var order_id = $(this).attr('d_order_id');
			var dia=$.dialog({
		        title:'温馨提示',
		        content: '确认不退货？',
		        button:["确认","取消"]
		    });
		    dia.on("dialog:action",function(e){
		    	if(e.index == 0){
		    		$.ajax({
		                url: "{:U('sureNotGoods')}",
		                type: 'get',
		                data: {
		                    order_id: order_id
		                },
		                dataType: 'json',
		                error: function () {
		                    $.tips({
						        content:'服务器连接失败',
						        stayTime:2000,
						        type:"success"
						    });
		                }, success: function (data) {
		                    if (data.status) {
		                        $.tips({
							        content:data.info,
							        stayTime:2000,
							        type:"success"
							    });

		                        document.location.reload();//当前页面  
		                    } else {
		                        $.tips({
							        content:data.info,
							        stayTime:2000,
							        type:"success"
							    });

		                    }
		                }
		            });
		    	}
		    });
		    dia.on("dialog:hide",function(e){
		        console.log("dialog hide")
		    });
		});
		
		var browser={ 
		versions:function(){ 
			var u = navigator.userAgent, app = navigator.appVersion; 
			return { 
			trident: u.indexOf('Trident') > -1, //IE内核 
			presto: u.indexOf('Presto') > -1, //opera内核 
			webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 
			gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 
			mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端 
			ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 
			android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器 
			iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器 
			iPad: u.indexOf('iPad') > -1, //是否iPad 
			webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部 
			};
			}()
		}
		
		var temp_order = '';
		function payNow(amount, discount, mall_orderId, shopId, userId) {
			temp_order = mall_orderId;
			//window.android.jsShopPayment(amount, discount, mall_orderId, shopId, userId);
			if(browser.versions.mobile&&browser.versions.ios&&browser.versions.iPhone||browser.versions.iPad){
				window.location.href = "js://" + encodeURIComponent('{"action":"pay","amount": "'+amount+'","discount":"'+discount+'","mall_orderId":"'+mall_orderId+'","shopId":"'+shopId+'","userId":"'+userId+'"}');
			}
			
			if(browser.versions.mobile&&browser.versions.android){
				window.wst.startFunction(amount, discount, mall_orderId, shopId, userId)
			}
	    }

		function onPayResultCallback(statusCode){
			if(statusCode == 0){
				var url = "{:U('PayBack/index')}";
				
				if( url.indexOf('?')>0 ){
					url += '&order_id=' + temp_order;
				}else{
					url += '?order_id=' + temp_order;
				}
				window.location.href = url;
			}else if(statusCode == 1){
				$.tips({
			        content:'支付失败！',
			        stayTime:2000,
			        type:"success"
			    });
			}else if(statusCode == 2){
				$.tips({
			        content:'用户取消',
			        stayTime:2000,
			        type:"success"
			    });
			}
		}

		$('.user_return_goods').tap(function(){
			var url = $(this).attr('_href');
			$.get("{:U('ReturnGoods/check_user_bank')}", function(r){
				if(r.status){
					window.location.href = url;
				}else{
					$.tips({
				        content:'系统检测你还未绑定银行卡！',
				        stayTime:2000,
				        type:"success"
				    });
				}
			}, 'json');
		});


		function goHome(){
			window.location.href="{:U('Index/sindex')}";
		}
	</script>
</block>